home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Systemmonitors / Snoopy / Sources / patch.asm < prev    next >
Assembly Source File  |  1996-09-26  |  7KB  |  238 lines

  1.  
  2.         incpath    include:
  3.         maclib    sm.mac
  4.         macfile    macro.i
  5.         macfile    snoopy.i
  6.         macfile    extern/main
  7.         macfile    macros/patch
  8.  
  9.         section    main,code
  10.  
  11. ***********************************************************************************
  12. ;--------------    this is the patch-function that replaces any original LIBRARY code.
  13. ;--------------    Note that we have a little recursion-protector here that will
  14. ;--------------    prevents recursions that occur inside the original vector 
  15. ;--------------    just aslong as the PatchCode() is active
  16. ;--------------    
  17.  
  18. ;--------------    NOTE: the device patch follows below & is a LOT more complicated
  19.  
  20.  
  21.         xdef    Patch_START
  22. Patch_START    dc.b    PATCH_IDSTRING    ; sphead_Ident
  23.         dc.l    0        ; sphead_Owner
  24.         dc.l    0        ; sphead_OriginalFunction
  25.  
  26.         xdef    PatchInfoStruct
  27. PatchInfoStruct    dc.l    0        ; sphead_Info
  28.         push    a0
  29.         lea    (recursionWord,pc),a0
  30.         tst.w    (a0)
  31.         bne.b    OriginalCode
  32.         move.w    #-1,(a0)
  33.         pop    a0
  34.         addq.l    #1,(ActiveCalls)
  35.         push    a6
  36.         bsr.b    SetupReplyMsg1
  37.         push    a6
  38.         movea.l    (4,sp),a6
  39.         xdef    OriginalVector0
  40. OriginalVector0    jsr    $ffff0000
  41.         pop    a6
  42.         bsr    SendReplyMsg1
  43.         lea    (recursionWord,pc),a6
  44.         clr.w    (a6)
  45.         pop    a6
  46.         subq.l    #1,(ActiveCalls)
  47.         rts
  48.  
  49. OriginalCode    pop    a0    ; from initial push at line #ß
  50.         xdef    OriginalVector1
  51. OriginalVector1    jsr    $ffff000
  52.         rts
  53.  
  54. ;--------------    HEY DUDES: I know this is a bit messy, but I couldn't think of
  55. ;--------------    anything better for my purpose. Of course, Snoopy will probably
  56. ;--------------    miss out one or two calls in "stress situations", but
  57. ;--------------    "better safe than sorry".....
  58. recursionWord    dc.w    0    ; if bit15 is 0, then no call is currently active 
  59.  
  60. ***********************************************************************************
  61. ;--------------    sets up the replymsg given by the patch function
  62. ;--------------    
  63. ;--------------    => d0-d7/a0-a5: Registers before function call
  64. ;--------------    <= a6: PatchCallMessage structure
  65. ;--------------    allocate data structure
  66. SetupReplyMsg1    pushm    d0-d7/a0-a5
  67.         movea.l    (execBase).w,a6
  68.         move.l    (thistask),d0
  69.         cmp.l    (ThisTask,a6),d0
  70.         beq    .SKIPTHIS
  71.         move.l    #smsg_SIZEOF,d0
  72.         move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  73.         CALL    AllocMem,<(execBase).w>
  74.         move.l    d0,a6
  75.         popm    d0-d7/a0-a5
  76.  
  77. ;--------------    fail if NULL; else save all registers
  78.         cmpa.l    #0,a6
  79.         beq    .FAIL
  80.         SAVEREGS smsg_RegsBeforeCall
  81. .FAIL        rts
  82. .SKIPTHIS    suba.l    a6,a6
  83.         popm    d0-d7/a0-a5
  84.         rts
  85.  
  86. ***********************************************************************************
  87. ;--------------    sends the reply message back
  88. ;--------------    
  89. ;--------------    => d0-d7/a0-a5: Registers after function call
  90. ;--------------    
  91. ;--------------    fail if NULL; else save all registers
  92. SendReplyMsg1    cmpa.l    #0,a6
  93.         beq    .FAIL
  94.         SAVEREGS smsg_RegsAfterCall
  95.         pushm    d0-d7/a0-a5
  96.  
  97.         movea.l    (execBase).w,a0
  98.         move.l    (ThisTask,a0),(smsg_Task,a6)
  99.         move.l    (PatchInfoStruct,pc),(smsg_Info,a6)
  100.         movea.l    a6,a5            ; a5 = Data structure
  101.         movea.l    a0,a6
  102.  
  103. ;--------------    setup other message stuff
  104.         move.b    #NT_MESSAGE,(LN_TYPE,a5)
  105.         move.w    #smsg_SIZEOF,(MN_LENGTH,a5)
  106.         move.w    #MSGTYPEF_LIBRARY,(smsg_Type,a5) ; **DO NOT REMOVE**
  107.         move.l    #0,(MN_REPLYPORT,a5)
  108.         move.l    (myport),a0        ; port
  109.         move.l    a5,a1            ; message
  110.         CALL    PutMsg
  111.  
  112. ;--------------    new: handle timeout
  113.         push    a6
  114.         movea.l    (PatchInfoStruct,pc),a1
  115.         move.l    (spatch_Timeout,a1),d1
  116.         beq.b    .NOTIMEOUT
  117.         cmpi.l    #-1,d1
  118.         beq.b    .BREAKOUT
  119.         BRBS.B    #31,d1,.NOTIMEOUT    ; skip negative timeout values
  120.         CALL    Delay,<(dosBase)>
  121.         bra.b    .NOTIMEOUT
  122. .BREAKOUT    move.l    #SIGBREAKF_CTRL_C,d0
  123.         CALL    Wait,<(execBase).w>
  124. .NOTIMEOUT    pop    a6
  125.  
  126.         popm    d0-d7/a0-a5
  127. .FAIL        rts
  128.  
  129.         xdef    Patch_SIZEOF
  130. Patch_SIZEOF    dc.l    *-Patch_START
  131.  
  132. ;--------------    Now the two patches for BeginIO()/AbortIO(); Both patches
  133. ;--------------    are very small and "minimalistic" (I had a much more complicated
  134. ;--------------    one in the beginning but it didn't work -> this one does ;-)
  135.  
  136.         xdef    BeginIO_Patch
  137. BeginIO_Patch:    dc.b    PATCH_IDSTRING    ; sphead_Ident
  138.         dc.l    0        ; sphead_Owner
  139.         dc.l    0        ; sphead_OriginalFunction
  140.         dc.l    0        ; sphead_Info (size of memory)
  141.         dc.l    0        ; sphead_DevicePtr
  142.  
  143. ;--------------    "here we go again with a funky intro": BeginIO gets the
  144. ;--------------    IOBlock in a1 and a pointer to the device in a6.
  145.         addq.l    #1,(ActiveCalls)
  146.         push    d4
  147.         move.l    (4,sp),d4
  148.         pushm    d0-d3/d5-d7/a0-a6
  149.         lea    (BeginIO_Patch,pc),a5
  150.         move.w    #MSGTYPEF_DEVICE|MSGTYPEF_BEGINIO,d5
  151.         jsr    PerformDevicePatch
  152.         popm    d0-d3/d5-d7/a0-a6
  153.         pop    d4
  154.         subq.l    #1,(ActiveCalls)
  155.         xdef    BeginIO_Jump
  156. BeginIO_Jump:    jsr    $ffff0000    ; proceed with IO call
  157.         rts
  158.         xdef    BeginIO_SIZEOF
  159. BeginIO_SIZEOF    dc.l    *-BeginIO_Patch
  160.  
  161.         xdef    AbortIO_Patch
  162. AbortIO_Patch:    dc.b    PATCH_IDSTRING    ; sphead_Ident
  163.         dc.l    0        ; sphead_Owner
  164.         dc.l    0        ; sphead_OriginalFunction
  165.         dc.l    0        ; sphead_Info (size of memory)
  166.         dc.l    0        ; sphead_DevicePtr
  167.         addq.l    #1,(ActiveCalls)
  168.         push    d4
  169.         move.l    (4,sp),d4
  170.         pushm    d0-d3/d5-d7/a0-a6
  171.         lea    (AbortIO_Patch,pc),a5
  172.         move.w    #MSGTYPEF_DEVICE,d5
  173.         jsr    PerformDevicePatch
  174.         popm    d0-d3/d5-d7/a0-a6
  175.         pop    d4
  176.         subq.l    #1,(ActiveCalls)
  177.         xdef    AbortIO_Jump
  178. AbortIO_Jump:    jsr    $ffff0000    ; proceed with IO call
  179.         rts
  180.         xdef    AbortIO_SIZEOF
  181. AbortIO_SIZEOF    dc.l    *-AbortIO_Patch
  182.  
  183.  
  184. **************************************************************************
  185. ;--------------    Really perform a device patch (because BeginIO()/AbortIO()
  186. ;--------------    really are *VERY* similar)
  187. ;--------------    
  188. ;--------------    => a5: APTR begin_of_patch
  189. ;--------------       d5: WORD flags
  190. ;--------------    
  191. ;--------------    Note: This function DOES NOT save any registers, the patches
  192. ;--------------    above have to take care of this!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  193. ;--------------    
  194.         ENTRY    PerformDevicePatch
  195.         move.l    a1,d6            ; d6 = pointer to IO block
  196.         move.l    #sdmsg_SIZEOF,d7    
  197.         add.l    (sphead_Info,a5),d7    ; d0 = size of allocated memory
  198.         move.l    d7,d0
  199.         move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  200.         CALL    AllocMem,<(execBase).w>
  201.         tst.l    d0
  202.         beq.b    PerformDevicePatch_done
  203.         movea.l    d0,a4
  204.         move.l    d4,(sdmsg_PC,a4)
  205.  
  206. ;--------------    copy IO block
  207.         move.l    (sphead_Info,a5),d0
  208.         subq.w    #1,d0
  209.         lea    (sdmsg_SIZEOF,a4),a1    ; target
  210.         movea.l    d6,a0            ; source
  211. .COPYMEMORY    move.b    (a0)+,(a1)+
  212.         dbra    d0,.COPYMEMORY
  213.  
  214. ;--------------    setup other message stuff
  215.         move.b    #NT_MESSAGE,(LN_TYPE,a4)
  216.         move.w    d7,(MN_LENGTH,a4)
  217.         move.l    (sphead_DevicePtr,a5),(sdmsg_DeviceBase,a4)
  218.         move.l    (ThisTask,a6),(sdmsg_Task,a4)
  219.         move.w    d5,(sdmsg_Type,a4) ; **DO NOT REMOVE**
  220.         move.l    #0,(MN_REPLYPORT,a4)
  221.  
  222. ;--------------    send message and immediately continue processing
  223.         move.l    (myport),a0        ; port
  224.         move.l    a4,a1            ; message
  225.         CALL    PutMsg
  226.         DONE    PerformDevicePatch
  227.  
  228.         section    memory,bss
  229.  
  230. ;--------------    *** DO NOT REMOVE THIS ***, its here just to make sure
  231. ;--------------    SLINK doesn't place the BSS section as the second section
  232. ;--------------    (DETACHSTARTUPARGS macro (see main.asm) relys on a certain
  233. ;--------------    section layout which could be scratched somehow)
  234.         ds.w    1
  235.  
  236. **************************************************************************
  237. ;--------------    
  238.